package com.tools.utils;

import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.util.Optional;

/**
 * 提示框
 *
 * @author < a href=" ">ZhangYang</ a>
 * @version v1.0.01
 * @date 2018-08-03 15:44:42
 */

public class AlertUtil {
  /**
   * 信息提示框
   *
   * @param message
   */
  public static void showInfoAlert(String message) {
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.getIcons().add(new Image("image/database.png"));
    alert.setHeaderText(null);
    alert.setContentText(message);
    alert.initStyle(StageStyle.UNIFIED);
    alert.show();
  }

  /**
   * 等待信息提示框
   *
   * @param message
   */
  public static void showAndWaitInfoAlert(String message) {
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.getIcons().add(new Image("image/database.png"));
    alert.setHeaderText(null);
    alert.setContentText(message);
    alert.initStyle(StageStyle.UNIFIED);
    alert.showAndWait();
  }

  /**
   * 注意提示框
   *
   * @param message
   */
  public static void showWarnAlert(String message) {
    Alert alert = new Alert(Alert.AlertType.WARNING);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.getIcons().add(new Image("image/database.png"));
    alert.setHeaderText(null);
    alert.setContentText(message);
    alert.initStyle(StageStyle.UNIFIED);
    alert.show();
  }

  /**
   * 异常提示框
   *
   * @param message
   */
  public static void showErrorAlert(String message) {
    Alert alert = new Alert(Alert.AlertType.ERROR);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.getIcons().add(new Image("image/database.png"));
    alert.setHeaderText(null);
    alert.setContentText(message);
    alert.initStyle(StageStyle.UNIFIED);
    alert.show();
  }

  /**
   * 确定提示框
   *
   * @param message
   */
  public static boolean showConfirmAlert(String message) {
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.getIcons().add(new Image("image/database.png"));
    alert.setHeaderText(null);
    alert.setContentText(message);
    alert.initStyle(StageStyle.UNIFIED);
    Optional<ButtonType> optional = alert.showAndWait();
    if (ButtonType.OK == optional.get()) {
      return true;
    } else {
      return false;
    }
  }
}
